package com.adayo.memoryfree.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.adayo.memoryfree.R;
import com.adayo.memoryfree.base.BaseSwipeBackActivity;
import com.adayo.memoryfree.fragment.AutoStartFragment;
import com.adayo.memoryfree.fragment.WeakFragmentPagerAdapter;
import com.adayo.memoryfree.utils.JDensityKit;
import com.adayo.memoryfree.widgets.SlidingTab;
import com.adayo.memoryfree.widgets.TitleView;

import org.xutils.view.annotation.ViewInject;

public class AutoStartManageActivity extends BaseSwipeBackActivity {

	@ViewInject(R.id.tv_title)
	private TitleView titleView;
	@ViewInject(R.id.tabs)
	SlidingTab tabs;
	@ViewInject(R.id.pagerFragmentTask)
	ViewPager pager;
	private MyPagerAdapter adapter;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_auto_start_manage;
	}

	@Override
	protected void initParams(Bundle savedInstanceState) {
		titleView.setResource(R.drawable.selector_return_btn,
				R.string.app_autostart_manage);
		titleView.setLeftClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		adapter = new MyPagerAdapter(getSupportFragmentManager());

		pager.setAdapter(adapter);

		int pageMargin = JDensityKit.getInstance(context).dp2px(4);
		pager.setPageMargin(pageMargin);

		tabs.setViewPager(pager);
		setTabsValue();
	}

	private void setTabsValue() {
		// 设置Tab是自动填充满屏幕的
		tabs.setShouldExpand(true);
		// 设置Tab的分割线是透明的
		tabs.setDividerColor(Color.TRANSPARENT);
		// 设置Tab底部线的高度
		tabs.setUnderlineHeight(JDensityKit.getInstance(context).dp2px(1));
		// 设置Tab Indicator的高度
		tabs.setIndicatorHeight(JDensityKit.getInstance(context).dp2px(3));
		// 设置Tab标题文字的大小
		tabs.setTextSize(JDensityKit.getInstance(context).sp2px(16));
		// 设置Tab Indicator的颜色
		tabs.setTextColor(Color.parseColor("#ffffff"));
		tabs.setIndicatorColor(Color.parseColor("#ffffff"));
		// 设置选中Tab文字的颜色 (这是我自定义的一个方法)
		tabs.setSelectedTextColor(Color.parseColor("#ffffff"));
		// 取消点击Tab时的背景色
		tabs.setTabBackground(0);
	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}


	public class MyPagerAdapter extends WeakFragmentPagerAdapter {
		private final String[] TITLES = {"普通软件", "系统核心软件"};

		public MyPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return TITLES[position];
		}

		@Override
		public int getCount() {
			return TITLES.length;
		}

		@Override
		public Fragment getItem(int position) {
			// return SuperAwesomeCardFragment.newInstance(position);return
			AutoStartFragment fragment = new AutoStartFragment();
			Bundle bundle = new Bundle();

			bundle.putInt("position", position);
			fragment.setArguments(bundle);
			saveFragment(fragment);

			return fragment;
		}
	}
}
